<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>首页 - BookAdmin图书管理系统</title>
    <link rel="icon" href="/images/favicon.ico" type="image/ico">
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link href="/css/materialdesignicons.min.css" rel="stylesheet">
<link rel="stylesheet" href="/js/bootstrap-multitabs/multitabs.min.css">
    <link rel="stylesheet" href="/js/jconfirm/jquery-confirm.min.css">
<link href="/css/style.min.css" rel="stylesheet">
</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
    <!--左侧导航-->
    <aside class="lyear-layout-sidebar">
      
      <!-- logo -->
      <div id="logo" class="sidebar-header">
        <a href="/index.html"><img src="/images/logo-sidebar.png" title="图书管理系统" alt="图书管理系统" /></a>
      </div>
      <div class="lyear-layout-sidebar-scroll"> 
        
        <nav class="sidebar-main">
          <ul class="nav nav-drawer">
            <li class="nav-item active"> <a href="/index.html"><i class="mdi mdi-home"></i> <span>后台首页</span></a> </li>
            <li class="nav-item nav-item-has-subnav" id="menu-basic">
              <a href="javascript:void(0)"><i class="mdi mdi-content-save"></i> <span>基础数据</span></a>
              <ul class="nav nav-subnav">
                <li> <a class="multitabs" href="/pages/basic/book.html">图书管理</a> </li>
                <li> <a class="multitabs" href="/pages/basic/category.html">分类管理</a> </li>
                <li> <a class="multitabs" href="/pages/basic/publisher.html">出版社管理</a> </li>
              </ul>
            </li>
              <li class="nav-item nav-item-has-subnav" id="menu-system">
                  <a href="javascript:void(0)"><i class="mdi mdi-settings"></i> <span>系统管理</span></a>
                  <ul class="nav nav-subnav">
                      <li> <a class="multitabs" href="/pages/system/user.html">用户管理</a> </li>
                  </ul>
              </li>
            <li class="nav-item nav-item-has-subnav" id="menu-business">
                <a href="javascript:void(0)"><i class="mdi mdi-format-align-justify"></i> <span>业务操作</span></a>
                <ul class="nav nav-subnav">
                    <li> <a class="multitabs" href="/pages/business/bookstock.html">库存管理</a> </li>
                    <li> <a class="multitabs" href="/pages/business/borrowing.html">借阅列表</a> </li>
                    <li> <a class="multitabs" href="/pages/business/borrower.html">读者数据</a> </li>
                </ul>
            </li>
            <li class="nav-item nav-item-has-subnav" id="menu-chart">
                <a href="javascript:void(0)"><i class="mdi mdi-poll"></i><span>图表分析</span></a>
                <ul class="nav nav-subnav">
                    <li> <a class="multitabs" href="/pages/report/report.html">展示图表</a> </li>
                </ul>
            </li>
            </ul>
        </nav>
        <div class="sidebar-footer">
          <p class="copyright">Copyright &copy; 2020. <a target="_blank" href="https://gitee.com/Cp1132344476/bookadmin">Chenp</a> All rights reserved.</p>
        </div>
      </div>
      
    </aside>
    <!--End 左侧导航-->
    
    <!--头部信息-->
    <header class="lyear-layout-header">
      
      <nav class="navbar navbar-default">
        <div class="topbar">
          
          <div class="topbar-left">
            <div class="lyear-aside-toggler">
              <span class="lyear-toggler-bar"></span>
              <span class="lyear-toggler-bar"></span>
              <span class="lyear-toggler-bar"></span>
            </div>
          </div>
          
          <ul class="topbar-right">
              <a href="javascript:void(0)" data-toggle="dropdown">
                <span id="span-username"><span class="caret"></span></span>
              </a>
              <ul class="dropdown-menu dropdown-menu-right">
                <li> <a href="javascript:updatePassword();"><i class="mdi mdi-lock-outline"></i> 修改密码</a> </li>
                <li class="divider"></li>
                <li> <a href="/logout"><i class="mdi mdi-logout-variant"></i> 退出登录</a> </li>
              </ul>
            </li>
          </ul>
          
        </div>
      </nav>
      
    </header>
    <!--End 头部信息-->
    
    <!--页面主要内容-->
    <main class="lyear-layout-content">
      
      <div id="iframe-content"></div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="/js/bootstrap-multitabs/multitabs.js"></script>
<script type="text/javascript" src="/js/index.min.js"></script>
<script src="js/jconfirm/jquery-confirm.min.js"></script>
<script type="text/javascript" src="/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/js/lightyear.js"></script>
<script type="text/javascript">
    var currentUser;
    $(function() {
        $.get("/user/current", function(data) {
            currentUser = data;
            let role = data.authorities[0].authority;
            if (role == "ROLE_BOOK") {  // 图书管理员, 隐藏系统管理菜单
                $("#span-username").html(data.username + "-图书管理员");
                $("#menu-system").css("display", "none");
            } else if (role == "ROLE_SYSTEM") { // 系统管理员, 隐藏业务操作菜单
                $("#span-username").html(data.username + "-系统管理员");
                $("#menu-business").css("display", "none");
            } else {
                $("#span-username").html(data.username + "-超级管理员");
            }
        }, "json");
    });

    function updatePassword() {
        $.confirm({
            title: '提示',
            content: '' +
                '<form id="form-password" class="formName">' +
                '<input type="hidden" name="username" value="'+currentUser.username+'"/>' +
                '<div class="form-group">' +
                '<label>旧密码</label>' +
                '<input type="password" placeholder="旧密码" name="oldPassword" class="name form-control" value="" required />' +
                '</div>' +
                '<div class="form-group">' +
                '<label>新密码</label>' +
                '<input type="password" placeholder="新密码" name="newPassword" class="name form-control" required />' +
                '</div>' +
                '</form>',
            buttons: {
                formSubmit: {
                    text: '提交',
                    btnClass: 'btn-blue',
                    action: function () {
                        $.post('/user/updatePassword', $("#form-password").serialize(), function(resp) {
                            if (resp.flag) {
                                window.location.href = '/logout';
                            } else {
                                lightyear.notify(resp.message, 'danger', 5000, 'mdi mdi-emoticon-happy', 'top', 'center');
                            }
                        });
                    }
                },
                cancel: {
                    text: '取消'
                },
            }
        });
    }
</script>
</body>
</html>